<template>
  <div id="Financial_Top">
    <div>
      <!--        面包屑-->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>订阅信息</el-breadcrumb-item>
      </el-breadcrumb>
      <!--        面包屑 end-->
      <!--        内容-->
      <el-card>
        <el-form ref="form" :model="searchForm" label-width="80px" :inline="true" size="small">
          <el-form-item label="">
            <el-col :span="11">
              <el-form-item prop="date1">
                <el-date-picker type="date" placeholder="选择日期" v-model="searchForm.start_time"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col class="line" :span="1">-</el-col>
            <el-col :span="11">
              <el-form-item prop="date1">
                <el-date-picker type="date" placeholder="选择日期" v-model="searchForm.end_time"
                                value-format="yyyy-MM-dd"
                                style="width: 100%;"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" @click="search">查询</el-button>
          </el-form-item>

          <el-form-item>
            总数：{{total}}
          </el-form-item>
        </el-form>
        <el-table
            :data="tableData"
            border
            style="width: 100%">
          <el-table-column
              prop="created_at"
              label="购买日期">
          </el-table-column>
          <el-table-column
              prop="amount"
              label="购买金额">
          </el-table-column>
          <el-table-column
              prop="title"
              label="小说标题">
          </el-table-column>
          <el-table-column
              prop="desc"
              label="详情">
          </el-table-column>
          <el-table-column
              prop="nickname"
              label="用户姓名">
          </el-table-column>
        </el-table>
        <div class="el-pagination">
          <el-pagination
              background
              @size-change="changeSize"
              @current-change="changeCurrent"
              :current-page="params.pagenum"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="params.pagesize"
              :layout="this.$store.state.paginationLayout"
              :total="params.totals">
          </el-pagination>
        </div>

      </el-card>
    </div>
    <el-dialog title="重审"   :width="this.$store.state.dialogWidth" :visible.sync="visible">
      <el-form ref="form" label-width="150px" size="small">
        <el-form-item label="重审说明">
          <el-input v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="visible=false" size="small">取 消</el-button>
                <el-button type="primary" @click="dialogAffirm" size="small">确 定</el-button></span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "Financial_Top",
  data() {
    return {
      params: {
        pagenum: 1,
        pagesize: 10,
        totals: 0,
      },
      searchForm: {
        start_time: '',
        end_time: '',
      },
      tableData: [],
      visible: false,
      imageUrl: '',
      form: {
        remark: '',
      },
      total: 0,
    }
  },
  created() {
    this.getList()
    this.searchForm.end_time = new Date().toISOString().substr(0, 10) // 获取今天的日期，格式为 "yyyy-MM-dd"
    const today = new Date();
    const yesterday = new Date(today);
    yesterday.setDate(today.getDate() - 1); // 设置日期为昨天

    this.searchForm.start_time = yesterday.toISOString().substr(0, 10)
  },
  methods: {
    getList() {
      let data = {
        page: this.params.pagenum,
        page_size: this.params.pagesize,
        start_time: this.searchForm.start_time,
        end_time: this.searchForm.end_time,
      };
      this.$axios.post("writer/submit/index", data).then((res) => {
        this.params.totals = res.data.count;
        this.tableData = res.data.list;
        this.total = 0
        if (res.data.list) {
          for (let row of res.data.list) {
            this.total += row.amount
          }
        }

      });
    },
    // 每页显示多少条
    changeSize(val) {
      this.params.pagesize = val;
      this.getList();
    },
    // 当前显示的页数
    changeCurrent(val) {
      this.params.pagenum = val;
      this.getList()
    },
    search() {
      this.params.pagenum = 1;
      this.getList();
    },
    dialogAffirm() {
      this.$axios.post("writer/mch_withdraw/reback", {id: this.id, remark: this.form.remark}).then((res) => {
        this.$message.success('成功!');
        this.visible = false;
        this.getList()
      });
    },
  }
}
</script>

<style scoped>

</style>